package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.SafetyExaminationPaperInfo;
import com.ruoyi.system.mapper.SafetyExaminationPaperInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SafetyExaminationPaperquestionMapper;
import com.ruoyi.system.domain.SafetyExaminationPaperquestion;
import com.ruoyi.system.service.ISafetyExaminationPaperquestionService;

/**
 * 试卷题目Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-04-07
 */
@Service
public class SafetyExaminationPaperquestionServiceImpl implements ISafetyExaminationPaperquestionService 
{
    @Autowired
    private SafetyExaminationPaperquestionMapper safetyExaminationPaperquestionMapper;
    @Autowired
    private SafetyExaminationPaperInfoMapper safetyExaminationPaperInfoMapper;
    /**
     * 查询试卷题目
     * 
     * @param id 试卷题目ID
     * @return 试卷题目
     */
    @Override
    public SafetyExaminationPaperquestion selectSafetyExaminationPaperquestionById(Long id)
    {
        return safetyExaminationPaperquestionMapper.selectSafetyExaminationPaperquestionById(id);
    }

    /**
     * 查询试卷题目列表
     * 
     * @param safetyExaminationPaperquestion 试卷题目
     * @return 试卷题目
     */
    @Override
    public List<SafetyExaminationPaperquestion> selectSafetyExaminationPaperquestionList(SafetyExaminationPaperquestion safetyExaminationPaperquestion)
    {
        return safetyExaminationPaperquestionMapper.selectSafetyExaminationPaperquestionList(safetyExaminationPaperquestion);
    }

    /**
     * 新增试卷题目
     * 
     * @param safetyExaminationPaperquestion 试卷题目
     * @return 结果
     */
    @Override
    public int insertSafetyExaminationPaperquestion(SafetyExaminationPaperquestion safetyExaminationPaperquestion)
    {
        return safetyExaminationPaperquestionMapper.insertSafetyExaminationPaperquestion(safetyExaminationPaperquestion);
    }

    /**
     * 修改试卷题目
     * 
     * @param safetyExaminationPaperquestion 试卷题目
     * @return 结果
     */
    @Override
    public int updateSafetyExaminationPaperquestion(SafetyExaminationPaperquestion safetyExaminationPaperquestion)
    {
        return safetyExaminationPaperquestionMapper.updateSafetyExaminationPaperquestion(safetyExaminationPaperquestion);
    }

    /**
     * 批量删除试卷题目
     * 
     * @param ids 需要删除的试卷题目ID
     * @return 结果
     */
    @Override
    public int deleteSafetyExaminationPaperquestionByIds(Long[] ids)
    {
        SafetyExaminationPaperInfo safetyExaminationPaperInfo = new SafetyExaminationPaperInfo();
        SafetyExaminationPaperquestion safetyExaminationPaperquestion = safetyExaminationPaperquestionMapper.selectSafetyExaminationPaperquestionById(ids[0]);
        safetyExaminationPaperInfo.setSafetyExaminationPaperId(safetyExaminationPaperquestion.getSafetyExaminationPaperId());
        safetyExaminationPaperInfo = safetyExaminationPaperInfoMapper.selectSafetyExaminationPaperInfoList(safetyExaminationPaperInfo).get(0);
        safetyExaminationPaperInfo.setSafetyExaminationQuestionAmount(safetyExaminationPaperInfo.getSafetyExaminationQuestionAmount()-ids.length);
        safetyExaminationPaperInfoMapper.updateSafetyExaminationPaperInfo(safetyExaminationPaperInfo);
        return safetyExaminationPaperquestionMapper.deleteSafetyExaminationPaperquestionByIds(ids);
    }

    /**
     * 删除试卷题目信息
     * 
     * @param id 试卷题目ID
     * @return 结果
     */
    @Override
    public int deleteSafetyExaminationPaperquestionById(Long id)
    {
        return safetyExaminationPaperquestionMapper.deleteSafetyExaminationPaperquestionById(id);
    }
}
